package com.hp.bon.sgw.wh.mml.repositories;

import java.util.Arrays;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.hp.bon.sgw.wh.mml.common.MMLConstants;

public class PropertyRepository {
	
	private static ConcurrentMap<String,String> properties = new ConcurrentHashMap<String,String>();
	
	public static String getPropertyValue(String propertyName){
		return properties.get(propertyName);
	}
	
	public static String getMMLCommandPrefix(String capabilityName){
		String prefix = properties.get(capabilityName);
		if(prefix!=null){
			return prefix.trim();
		}
		if(MMLConstants.CAP_RECH_EVC_PPSUSER.equalsIgnoreCase(capabilityName)){
			return MMLConstants.CMD_RECH_EVC_PPSUSER;
		}
		if(MMLConstants.CAP_LIST_EVC_TERMUSER.equalsIgnoreCase(capabilityName)){
			return MMLConstants.CMD_LIST_EVC_TERMUSER;
		}
		if(MMLConstants.CAP_CANCEL_EVC_RECH.equalsIgnoreCase(capabilityName)){
			return MMLConstants.CMD_CANCEL_EVC_RECH;
		}
		if(MMLConstants.CAP_LIST_EVC_STK.equalsIgnoreCase(capabilityName)){
			return MMLConstants.CMD_LIST_EVC_STK;
		}
		return "";
	}
	
	public static void addProperty(String name, String value){
		if(name==null || value==null){
			return;
		}
		properties.put(name, value);
	}	
	public static String getUserId(){
		String user = properties.get("UserId");
		if(user==null){
			user = "system";			
		}
		return user;
	}	
	public static String getPassword(){
		String ps = properties.get("Password");
		if(ps==null){
			ps = "system";			
		}
		return ps;		
	}
	public static String getTermIdentity(){
		String term = properties.get("Term");
		if(term==null){
			term = "00000000";			
		}
		return term;
	}
	
	//VC
	public static String getVCHost(){
		return properties.get("VCHost");
	}
	public static int getVCPort(){
		String port = properties.get("VCPort");
		return Integer.parseInt(port);
	}
	public static String getMMLVersion(){
		String version = properties.get("MMLVersion");
		if(version == null || version.trim().isEmpty()){
			return "1.00";
		}
		return version.trim();
	}
	public static String getMMLLanguage(){
		return getPropertyValue("MMLLanguage");
	}
	public static String getMMLLoginSN(){
		return getPropertyValue("MMLLoginServiceName");
	}
	public static String getMMLLogoutSN(){
		return getPropertyValue("MMLLogoutServiceName");
	}
	
	//Ctrl
	public static long getMsgTimeout(){
		String timeoutStr = properties.get("MsgTimeout");
		if(timeoutStr==null){
			timeoutStr = "300";
		}
		return Long.parseLong(timeoutStr);
	}	
	public static HashSet<String> getAuthorizationCapability(){
		HashSet<String> capabilities = new HashSet<String>();
		String caps = properties.get("ZBVCCapability");
		if(caps!=null && !caps.trim().isEmpty()){
			String[] tmpArr = caps.split(";");
			capabilities.addAll(Arrays.asList(tmpArr));
		}
		return capabilities;
	}
	public static String getLogMsgPath(){
		String ps = properties.get("log.msg.path");
		if(ps==null){
			ps = "./log/vcmsg/";			
		}
		return ps;
	}
	public static boolean isLogMsgEnable(){
		String ps = properties.get("log.msg.enable");
		if("true".equalsIgnoreCase(ps)){
			return true;		
		}
		return false;
	}
}
